home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / nktools.zip / CASES.ASM < prev    next >
Assembly Source File  |  1990-05-08  |  5KB  |  180 lines

  1. ;=======================================================================
  2. ; MODULE NAME:  Cases.ASM
  3. ; DEPENDENCIES: (None)
  4. ; LAST MOD ON:  9005.08
  5. ; PROGRAMMER:   Naoto Kimura
  6. ;
  7. ;     This is the assembly code for the routines in the StrUtil unit.
  8. ; Many of the routines were rewritten in the hopes that it will not
  9. ; only reduce the memory requirement, but also reduce the execution
  10. ; time.
  11. ;
  12. ;     This file should be assembled with Turbo Assembler.  If you need
  13. ; to use another assembler, then you should keep some things in mind.
  14. ;
  15. ; The TPASCAL memory model sets up automatically:
  16. ; * the standard Turbo Pascal entry code
  17. ;      push bp
  18. ;      mov bp,sp
  19. ; * the standard Turbo Pascal exit code
  20. ;      pop bp
  21. ;      ret n
  22. ; * the order of the arguments don't need to be reversed in the
  23. ;   assembly code.
  24. ;-----------------------------------------------------------------------
  25. ; 9001.20     Naoto Kimura
  26. ;             * Initial version created
  27. ;
  28. ; Modification history:
  29. ;
  30. ; 9002.14     Naoto Kimura
  31. ;             * Fixed bug in UpperStr and LowerStr routines (involved
  32. ;               weird bug(?) in assembler) :
  33. ;
  34. ;                   mov al,[bl+TBL]   ====>  mov al,[bx+TBL]
  35. ;
  36. ; 9002.23     Naoto Kimura
  37. ;             * Started to optimize some of the functions by rewriting
  38. ;               the translating functions to use the XLAT instruction.
  39. ; 9005.05     Naoto Kimura
  40. ;             * Broke up assembler modules into separate files to try
  41. ;               to decrease overhead (although the overhead is pretty
  42. ;               small, it's always nice to make available whatever
  43. ;               memory the user can use).
  44. ;=======================================================================
  45. .MODEL   TPASCAL
  46. LOCALS
  47.  
  48. .DATA
  49.  
  50. EXTRN    UpperTbl:BYTE
  51. EXTRN    LowerTbl:BYTE
  52. EXTRN    StdLower:BYTE
  53.  
  54. .CODE
  55.  
  56. ;-----------------------------------------------------------------------
  57. ;FUNCTION LoCase ( C : Char ) : Char
  58. ;
  59. ;     This function performs the opposite function as the UpCase
  60. ; function; it takes an upper case character and transforms it into
  61. ; its lower case form.
  62. ;
  63. ; REGISTER USAGE:  AX    -- Return value
  64. ;                  BX    -- Destroyed
  65. ;-----------------------------------------------------------------------
  66. LoCase        PROC FAR C:BYTE
  67.         PUBLIC    LoCase
  68.         mov    al,[C]
  69.         mov    bx,OFFSET StdLower
  70.         xlat
  71.         ret
  72. LoCase        ENDP
  73.  
  74. ;-----------------------------------------------------------------------
  75. ;FUNCTION LoCase2 ( C : Char ) : Char
  76. ;
  77. ;     This function performs the opposite function as the UpCase
  78. ; function; it takes an upper case character and transforms it into
  79. ; its lower case form.
  80. ;
  81. ; REGISTER USAGE:  AX    -- Return value
  82. ;                  BX    -- Destroyed
  83. ;-----------------------------------------------------------------------
  84. LoCase2        PROC FAR C:BYTE
  85.         PUBLIC    LoCase2
  86.         mov    al,[C]
  87.         mov    bx,OFFSET LowerTbl
  88.         xlat
  89.         ret
  90. LoCase2        ENDP
  91.  
  92. ;-----------------------------------------------------------------------
  93. ;FUNCTION UpCase2 ( C : Char ) : Char
  94. ;
  95. ;     This function performs the opposite function as the UpCase
  96. ; function; it takes an upper case character and transforms it into
  97. ; its lower case form.
  98. ;
  99. ; REGISTER USAGE:  AX    -- Return value
  100. ;                  BX    -- Destroyed
  101. ;-----------------------------------------------------------------------
  102. UpCase2        PROC FAR C:BYTE
  103.         PUBLIC    UpCase2
  104.         mov    al,[C]
  105.         mov    bx,OFFSET UpperTbl
  106.         xlat
  107.         ret
  108. UpCase2        ENDP
  109.  
  110. ;-----------------------------------------------------------------------
  111. ;FUNCTION UpperStr ( S : String ) : String
  112. ;
  113. ;     This function returns the passed string with all the lower case
  114. ; characters transformed into upper case characters.
  115. ;
  116. ; REGISTER USAGE:  AX            -- Return value
  117. ;                  BX,CX,DI,SI,ES    -- Destroyed
  118. ;-----------------------------------------------------------------------
  119. UpperStr    PROC FAR S:DWORD  RETURNS Result:DWORD
  120.         PUBLIC    UpperStr
  121.         USES    DS
  122.         mov    dx,SEG DATA
  123.         les    di,[Result]    ; get addr of function result
  124.         lds    si,[S]        ; get addr of function parameter
  125.         xor    ax,ax
  126.         cld            ; forward string op
  127.         lodsb            ; get length
  128.         stosb            ; copy length
  129.         or    ax,ax        ; null string ?
  130.         jz    @@done
  131.         mov    cx,ax
  132.         mov    bx,OFFSET UpperTbl
  133.         xor    ax,ax
  134. @@copy:        lodsb
  135.         push    ds
  136.         mov    ds,dx
  137.         xlat            ; transform
  138.         pop    ds
  139.         stosb
  140.         loop    @@copy
  141. @@done:        mov    ds,dx
  142.         ret
  143. UpperStr    ENDP
  144.  
  145. ;-----------------------------------------------------------------------
  146. ;FUNCTION LowerStr ( S :String ): String
  147. ;
  148. ;     This function returns the passed string with all the upper case
  149. ; characters transformed into lower case characters.
  150. ;
  151. ; REGISTER USAGE:  AX            -- Return value
  152. ;                  BX,CX,DI,SI,ES    -- Destroyed
  153. ;-----------------------------------------------------------------------
  154. LowerStr    PROC FAR S:DWORD RETURNS Result:DWORD
  155.         PUBLIC    LowerStr
  156.         mov    dx,ds
  157.         les    di,[Result]    ; get addr of function result
  158.         lds    si,[S]        ; get addr of function parameter
  159.         xor    ax,ax
  160.         cld            ; forward string op
  161.         lodsb            ; get length
  162.         stosb            ; copy length
  163.         or    ax,ax        ; null string ?
  164.         jz    @@done
  165.         mov    cx,ax
  166.         mov    bx,OFFSET LowerTbl
  167.         xor    ax,ax
  168. @@copy:        lodsb
  169.         push    ds
  170.         mov    ds,dx
  171.         xlat            ; transform
  172.         pop    ds
  173.         stosb
  174.         loop    @@copy
  175. @@done:        mov    ds,dx
  176.         ret
  177. LowerStr    ENDP
  178.  
  179. END
  180.